from django.db import models

PRES = (
	('A', 'Apress'),
	('B', "O'Reilly"),
	('C', 'Others'),
)

class Tag(models.Model):
	'''Tags collection'''
	name = models.CharField(max_length=300)
	
	def __unicode__(self):
		return self.name

class Book(models.Model):
	'''Book information'''
	title = models.CharField(max_length=300)
	author = models.CharField(max_length=100)
	press = models.CharField(max_length=1, choices=PRES)
	intro = models.TextField('Introduction')
	pages = models.IntegerField('number of pages')
	pub_date = models.DateField('Published date')
	isbn = models.CharField('ISBN', max_length=20)
	tags = models.ManyToManyField(Tag, through='Tagging')
	num_copy = models.IntegerField('number of copy')

	def __unicode__(self):
		return self.title

class Tagging(models.Model):
	'''intermediary for many-to-many relations''' 
	tag = models.ForeignKey(Tag)
	book = models.ForeignKey(Book)

	def __unicode__(self):
		return ''
